/*
 * DebugToFile.java
 * 
 * This file is part of Netuno Psamata.
 * 
 * CajuScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3, or (at your option) 
 * any later version.
 * 
 * CajuScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with CajuScript.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.netuno.psamata;

import java.io.*;

/**
 * Debug to File.
 * @author eduveks
 */
public class DebugToFile {
    /**
     * File output.
     */
    private FileOutputStream fos;
    /**
     * Debug to File.
     * @param file File to be write the debug messages.
     * @throws java.io.IOException IO Exception
     */
    public DebugToFile(String file) throws IOException {
        fos = new FileOutputStream(file, true);
    }
    /**
     * Write line.
     * @param content Content
     * @throws java.io.IOException IO Exception
     */
    public void println(String content) throws IOException {
        fos.write((content + "\r\n").getBytes());
    }
    /**
     * Write.
     * @param content Content
     * @throws java.io.IOException IO Exception
     */
    public void print(String content) throws IOException {
        fos.write((content).getBytes());
    }
    /**
     * Write an Exception.
     * @param e Exception
     * @throws java.io.IOException IO Exception
     */
    public void print(Exception e) throws IOException {
        e.printStackTrace(new PrintStream(fos));
    }
    /**
     * Flush.
     * @throws java.io.IOException IO Exception
     */
    public void flush() throws IOException {
        fos.flush();
    }
    /**
     * Close.
     * @throws java.io.IOException IO Exception
     */
    public void close() throws IOException {
        fos.close();
    }
}
